package org.budo.validation.aop.interceptor;

import java.lang.annotation.Annotation;

import org.budo.validation.validator.BudoValidator;
import org.budo.validation.validator.factory.BudoValidatorFactory;
import org.springframework.core.annotation.Order;

/**
 * @author lmw
 */
@Order(1020)
public class BudoValidationMethodInterceptor extends AbstractBudoValidationMethodInterceptor {
    @Override
    protected void validationMethodArgument(Integer parameterIndex, String parameterName, Object argumentValue, Annotation[] parameterAnnotations) {
        for (Annotation annotation : parameterAnnotations) {
            BudoValidatorFactory validatorFactory = this.getBudoValidatorFactory();
            Class<? extends Annotation> annotationType = annotation.annotationType();
            BudoValidator validator = validatorFactory.getValidator(annotationType);
            if (null != validator) {
                validator.validate(annotation, parameterIndex, parameterName, argumentValue);
            }
        }
    }
}
